const Router = require('koa-router')
const {
  userVerify,
  passwordHandle,
  loginVerify,
  passwordVerify
} = require('../middleware/user.middleware')
const {
  verifyAuth
} = require('../middleware/auth.middleware')
const { create, login, loginMobile } = require('../controller/user.controller')
const userRouter = new Router({ prefix: '/users' })

userRouter.post('/register', userVerify, passwordHandle, create)
userRouter.post('/login', loginVerify, passwordHandle, passwordVerify, login)
userRouter.post('/login_mobile', loginMobile, login)
userRouter.get('/auth', verifyAuth, (ctx, next) => {
  ctx.body = {
    status: 200,
    msg: '授权成功~',
    user: ctx.user
  }
})


module.exports = userRouter